package com.example.flower_shop.controller.adm;

import com.example.flower_shop.common.PageResult;
import com.example.flower_shop.service.adm.AdmUserService;
import com.example.flower_shop.vo.user.AdmUserPageReqVO;
import com.example.flower_shop.vo.user.AdmUserPageRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

/**
 * 后台用户管理
 */
@Tag(name = "后台用户管理")
@RestController
@RequestMapping("/api/admin/user")
public class AdmUserController {

    @Resource
    private AdmUserService admUserService;

    /**
     * 获取用户列表
     *
     * @param reqVO 请求体，包含分页信息和查询条件
     * @return 分页结果，包含用户列表和分页信息
     */
    @GetMapping("")
    @Operation(summary = "获取用户列表")
    public PageResult<AdmUserPageRespVO> list(@Valid AdmUserPageReqVO reqVO) {
        return admUserService.list(reqVO);
    }

    /**
     * 更改用户状态
     *
     * @param userId 用户ID
     */
    @PutMapping("/status/{userId}")
    @Operation(summary = "更改用户状态")
    public void changeStatus(@PathVariable Long userId) {
        admUserService.changeStatus(userId);
    }

    /**
     * 批量删除用户
     *
     * @param ids 需要删除的用户ID数组
     * @return 删除成功的数量
     */
    @DeleteMapping
    @Operation(summary = "批量删除用户", method = "DELETE",
            parameters = {
                    @Parameter(name = "ids", description = "用户id集合", required = true)
            })
    public int delete(@RequestParam Long[] ids) {
        return admUserService.deleteByIds(ids);
    }

}
